/************************************************************
  *  * EaseMob CONFIDENTIAL 
  * __________________ 
  * Copyright (C) 2013-2014 EaseMob Technologies. All rights reserved. 
  *  
  * NOTICE: All information contained herein is, and remains 
  * the property of EaseMob Technologies.
  * Dissemination of this information or reproduction of this material 
  * is strictly forbidden unless prior written permission is obtained
  * from EaseMob Technologies.
  */

#import "NSDateFormatter+Category.h"

static NSDateFormatter * _dataFormatter = nil;
@implementation NSDateFormatter (Category)

+ (instancetype)dateFormatter
{
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        _dataFormatter = [[self alloc] init];
    });
    return _dataFormatter;
}

+ (id)dateFormatterWithFormat:(NSString *)dateFormat
{
    NSDateFormatter *dateFormatter = [self dateFormatter];
    dateFormatter.dateFormat = dateFormat;
    return dateFormatter;
}

+ (id)defaultDateFormatter
{
    return [self dateFormatterWithFormat:@"yyyy-MM-dd HH:mm:ss"];
}
+ (NSString*)defaultDateTime:(NSString*)unixTime {
    
    return [self dateTimeToStringTime:unixTime formatte:@"yyyy-MM-dd HH:mm:ss"];
}
+(NSString *)dateTimeToStringTime:(NSString *)strUnixTime formatte:(NSString *)formatte
{
    if (strUnixTime.length == 0) {
        return nil;
    }
    
    NSDate *date = [NSDate dateWithTimeIntervalSince1970:[strUnixTime longLongValue]];
    
    if (date == nil) {
        return nil;
    }
    NSDateFormatter *dateFormatter = [self dateFormatter];
    [dateFormatter
     setTimeZone:[NSTimeZone localTimeZone]];
   
    [dateFormatter setDateFormat:formatte];
    
    NSString *date1= [dateFormatter stringFromDate:date];
    return date1;
    
}

@end
